﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;

namespace PCLawPrototype
{
    public partial class DStarter : DevExpress.XtraBars.Ribbon.RibbonForm
    {
            ManageClient manageClient = new ManageClient();
            ManageContact manageContact = new ManageContact();
            ManageLawyer manageLawyer = new ManageLawyer();
            ManageMatter manageMatter = new ManageMatter();
            ManageTask manageTask = new ManageTask();
            ManageInvoice manageInvoice = new ManageInvoice();
            ManageExpensesIncurred manageExpenses = new ManageExpensesIncurred();

        public DStarter()
        {
            InitializeComponent();

            System.Windows.Forms.ContextMenu cmnContext = new ContextMenu();
            this.ContextMenu = cmnContext;

            MenuItem mnuItem = new MenuItem("Cascade Windows");

            this.SetRPEventVisible(false);

            this.rpgClient.Visible = false;
            this.rpgMatter.Visible = false;
            this.rpgContact.Visible = false;
            this.rpgExpenses.Visible = false;
            this.rpgInvoice.Visible = false;
            this.rpgLawyer.Visible = false;
            this.rpgTask.Visible = false;

            manageClient.MdiParent = this;

            manageContact.MdiParent = this;

            manageLawyer.MdiParent = this;

            manageMatter.MdiParent = this;

            manageTask.MdiParent = this;

            manageInvoice.MdiParent = this;

            manageExpenses.MdiParent = this;
        }

        private void btnMClient_ItemClick(object sender, ItemClickEventArgs e)
        {
            manageClient.Show();
            if (manageClient.Visible)
            {
                manageClient.Focus();
            }
        }

        private void btnMContact_ItemClick(object sender, ItemClickEventArgs e)
        {
            manageContact.Show();
            if (manageContact.Visible)
            {
                manageContact.Focus();
            }
        }

        private void btnMLawyer_ItemClick(object sender, ItemClickEventArgs e)
        {
            manageLawyer.Show();
            if (manageLawyer.Visible)
            {
                manageLawyer.Focus();
            }
        }

        private void btnMMatter_ItemClick(object sender, ItemClickEventArgs e)
        {
            manageMatter.Show();
            if (manageMatter.Visible)
            {
                manageMatter.Focus();
            }
        }

        private void btnMTask_ItemClick(object sender, ItemClickEventArgs e)
        {
            manageTask.Show();
            if (manageTask.Visible)
            {
                manageTask.Focus();
            }
        }

        private void btnMInvoice_ItemClick(object sender, ItemClickEventArgs e)
        {
            manageInvoice.Show();
            if (manageInvoice.Visible)
            {
                manageInvoice.Focus();
            }
        }

        private void btnMExpense_ItemClick(object sender, ItemClickEventArgs e)
        {
            manageExpenses.Show();
            if (manageExpenses.Visible)
            {
                manageExpenses.Focus();
            }
        }

        private void btnMReport_ItemClick(object sender, ItemClickEventArgs e)
        {
            MessageBox.Show("Report will be shown!");
        }

        private void btnAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).Add();
        }

        private void btnEdit_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).Edit();
        }

        private void btnDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).Delete();
        }

        private void btnReload_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).Reload();
        }

        private void btnActive_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).Active();
        }

        private void btnViewContact_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).ViewContact();
        }

        private void btnViewMatter_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).ViewMatter();
        }

        private void btnViewTask_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).ViewTask();
        }

        private void beiClient_ItemPress(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).ViewPUClient();
        }

        private void beiMatter_ItemPress(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).ViewPUMatter();
        }

        private void btnSearch_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).StartSearch();
        }

        private void btnMakeAPayment_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.ActiveMdiChild != null)
                ((ManageRibbonForm)this.ActiveMdiChild).MakeAPayment();
        }

        public void ChangeActiveText(string text)
        {
            btnActive.Caption = text;
            if (text.Equals("Deac&tive"))
            {
                btnActive.Glyph = global::PCLawPrototype.Properties.Resources.plugin_delete;
                btnActive.LargeGlyph = global::PCLawPrototype.Properties.Resources.plugin_delete;
            }
            else
            {
                btnActive.Glyph = global::PCLawPrototype.Properties.Resources.plugin_link;
                btnActive.LargeGlyph = global::PCLawPrototype.Properties.Resources.plugin_link;
            }
        }
        public string GetActiveText()
        {
            return btnActive.Caption;
        }
        public void SetActiveVisible(bool visible)
        {
            this.btnActive.Visibility = visible ? BarItemVisibility.Always : BarItemVisibility.Never;
        }
        public void SetRPGClientVisible(bool visible)
        {
            this.rpgClient.Visible = visible;
        }
        public void SetRPGMatterVisible(bool visible)
        {
            this.rpgMatter.Visible = visible;
        }
        public void SetRPGContactVisible(bool visible)
        {
            this.rpgContact.Visible = visible;
        }
        public void SetRPGExpensesVisible(bool visible)
        {
            this.rpgExpenses.Visible = visible;
        }
        public void SetRPGInvoiceVisible(bool visible)
        {
            this.rpgInvoice.Visible = visible;
        }
        public void SetRPGLawyerVisible(bool visible)
        {
            this.rpgLawyer.Visible = visible;
        }
        public void SetRPGTaskVisible(bool visible)
        {
            this.rpgTask.Visible = visible;
        }
        public void SetEventFocus()
        {
            this.ribbon.SelectedPage = this.rpEvent;
        }
        public void SetRPEventVisible(bool visible)
        {
            this.rpEvent.Visible = visible;
            this.rpcFeature.Visible = visible;
        }

        private void bsiAWCascade_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.LayoutMdi(MdiLayout.Cascade);
        }

        private void bsiAWHorizontal_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void bsiAWVertical_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileVertical);
        }

        private void ribbon_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
                pumContext.ShowPopup(Control.MousePosition);
        }

        private void DStarter_MdiChildActivate(object sender, EventArgs e)
        {
            this.SetRPEventVisible(true);
            this.SetEventFocus();
        }
    }
}